package com.wunong.smart.commission.domain.model;

import com.wunong.smart.commission.client.enums.CommissionStatusEnum;
import com.wunong.smart.domain.platform.common.BizSource;
import com.wunong.smart.domain.platform.common.ICode;
import com.wunong.smart.domain.platform.entify.BaseModel;
import com.wunong.smart.domain.platform.entify.User;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.time.LocalDateTime;

/**
 * 代办事项
 *
 * @author create by zealot.zt
 */
@Getter
@Setter
@ToString(callSuper = true)
public class CommissionDomain extends BaseModel {

    /**
     * 用户信息
     */
    private User user;

    /**
     * 用户编号
     */
    private Long userId;

    /**
     * 用户角色
     */
    private Integer userRole;

    /**
     * 业务信息
     */
    private BizSource source;

    /**
     * 代办类型
     */
    private String commissionType;

    /**
     * 代办状态
     */
    private CommissionStatusEnum statusEnum;

    /**
     * 结束时间
     */
    private LocalDateTime finishTime;

    /**
     * 代办内容
     */
    private String content;

    public static CommissionDomain of() {
        return new CommissionDomain();
    }

    public static CommissionDomain ofInitial() {
        CommissionDomain domain = new CommissionDomain();
        domain.setStatusEnum(CommissionStatusEnum.PROCESSING);
        return domain;
    }

    public boolean isActive() {
        return statusEnum == CommissionStatusEnum.PROCESSING;
    }

    public void finish() {
        this.statusEnum = CommissionStatusEnum.FINISHED;
    }

    public void cancel() {
        this.statusEnum = CommissionStatusEnum.CANCELED;
    }

    public Integer getStatus() {
        return ICode.withCode(statusEnum);
    }

}
